package src.model.gameObject.eventBrokers;

import src.model.gameObject.GameObject;
import src.model.gameObject.ability.Health;
import src.model.gameObject.eventInterfaces.HealthListener;

import java.util.HashMap;

/**
 * sdffsdfsdafdsa  This handles events where the Health of a GameObject needs modification. Things such as attacking,
 * healing, etc. will need to notify the Health that it is to be modified.
 * 
 * @author Tristan
 *
 */
public class HealthEventBroker {
	private static HealthEventBroker staticReference;
	private HashMap<GameObject, HealthListener> GameObjectsHealth;
	
	/**
	 * Creates a new instance if HealthEventBroker.
	 */
	public HealthEventBroker(){
		
		
		GameObjectsHealth = new HashMap<GameObject, HealthListener>();
	}
	
	/**
	 * This registers a GameObject and its health with the event manager. This allows that when the GameObject
	 * is attacked, its health gets the memo.
	 * 
	 * @param go The GameObject being attacked.
	 * @param h The Health of the GameObject being attacked.
	 */
	public static void register(GameObject go, Health h){
		staticReference.GameObjectsHealth.put(go, h);
	}
	
	/**
	 * This unregisters the GameObject and its Health from the event manager. The GameObject and its Health
	 * will no longer take damage. This is useful if, for instance, the GameObject is destroyed.
	 * 
	 * @param go The GameObject that is being unregistered from the EventManager.
	 */
	public static void unregister(GameObject go){
		staticReference.GameObjectsHealth.remove(go);
	}
	
	/**
	 * This is the method for the event call. When this is called, the Health belonging to the 
	 * GameObject specified will change by the specified amount. 
	 * 
	 * @param go The GameObject having its Health modified.
	 * @param modifyAmount The ammount to modify it by. Positive heals. Negative damages.
	 */
	public static void notifyModifyHealth(GameObject go, float modifyAmount){
		HealthListener wantedHealth = staticReference.GameObjectsHealth.get(go);
		wantedHealth.notifyHealthEvent(modifyAmount);
	}
}
